package com.colin.jipay.weidian;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ThreadUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.colin.jipay.bean.WDTransBean;
import com.colin.jipay.utils.Constants;
import com.colin.jipay.utils.FileUtils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.List;
import java.util.concurrent.TimeUnit;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;

public class WDHelper {

    // 获取指定名称的类声明的类成员变量、类方法、内部类的信息
    public static void dumpClass(Class<?> actions) {

        XposedBridge.log("Dump class " + actions.getName());
        XposedBridge.log("Methods");

        // 获取到指定名称类声明的所有方法的信息
        Method[] m = actions.getDeclaredMethods();
        // 打印获取到的所有的类方法的信息
        for (int i = 0; i < m.length; i++) {

            XposedBridge.log(m[i].toString());
        }

        XposedBridge.log("Fields");
        // 获取到指定名称类声明的所有变量的信息
        Field[] f = actions.getDeclaredFields();
        // 打印获取到的所有变量的信息
        for (int j = 0; j < f.length; j++) {

            XposedBridge.log(f[j].toString());
        }

        XposedBridge.log("Classes");
        // 获取到指定名称类中声明的所有内部类的信息
        Class<?>[] c = actions.getDeclaredClasses();
        // 打印获取到的所有内部类的信息
        for (int k = 0; k < c.length; k++) {

            XposedBridge.log(c[k].toString());
        }
    }

    public static Object objOrder;

    /**
     * hook到订单生成的方法，得到新的订单数据
     */
    public static void hookOrderConfirm(ClassLoader classLoader) {
        XposedHelpers.findAndHookMethod("com.vdian.transaction.vap.buy.model.ConfirmOrderRespProxyDTO"
                , classLoader
                , "setPvid"
                , String.class
                , new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                        XposedBridge.log("hook到ConfirmOrderRespProxyDTO的setPvid方法");
                    }

                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        objOrder = param.thisObject;
                        ThreadUtils.executeByCpuWithDelay(new ThreadUtils.SimpleTask<Object>() {
                            @Nullable
                            @Override
                            public Object doInBackground() throws Throwable {
                                return null;
                            }

                            @Override
                            public void onSuccess(@Nullable Object result) {
                                String pvid = (String) XposedHelpers.callMethod(objOrder, "getPvid");
                                String IsDegraded = (String) XposedHelpers.callMethod(objOrder, "getIsDegraded");
                                String totalPayPrice = (String) XposedHelpers.callMethod(objOrder, "getTotalPayPrice");
                                String totalSavePrice = (String) XposedHelpers.callMethod(objOrder, "getTotalSavePrice");
                                LogUtils.i(pvid, IsDegraded, totalPayPrice, totalSavePrice);
                            }
                        }, 3, TimeUnit.SECONDS);

                    }
                });
    }

    /**
     * hook到订单生成的方法，得到新的订单数据
     */
    public static void hookOrderCreated(ClassLoader classLoader) {
        XposedHelpers.findAndHookMethod("com.vdian.transaction.vap.buy.model.CreateOrderRespProxyDTO"
                , classLoader
                , "setUrl"
                , String.class
                , new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                        XposedBridge.log("hook到ConfirmOrderRespProxyDTO的setPvid方法");
                    }

                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        objOrder = param.thisObject;
                        ThreadUtils.executeByCpuWithDelay(new ThreadUtils.SimpleTask<Object>() {
                            @Nullable
                            @Override
                            public Object doInBackground() throws Throwable {
                                return null;
                            }

                            @Override
                            public void onSuccess(@Nullable Object result) {
                                String errorMsg = (String) XposedHelpers.callMethod(objOrder, "getErrorMsg");
                                String orderId = (String) XposedHelpers.callMethod(objOrder, "getOrderId");
                                String payMode = (String) XposedHelpers.callMethod(objOrder, "getPayMode");
                                String pvid = (String) XposedHelpers.callMethod(objOrder, "getPvid");
                                String riskSign = (String) XposedHelpers.callMethod(objOrder, "getRiskSign");
                                String sign = (String) XposedHelpers.callMethod(objOrder, "getSign");
                                String tradeStatus = (String) XposedHelpers.callMethod(objOrder, "getTradeStatus");
                                String url = (String) XposedHelpers.callMethod(objOrder, "getUrl");
                                LogUtils.i(errorMsg, orderId, payMode, pvid, riskSign, sign, tradeStatus, url);
                            }
                        }, 3, TimeUnit.SECONDS);

                    }
                });
    }

    /**
     * hook到订单列表的所有订单数据
     */
    public static void hookOrderAdapterGetList(ClassLoader classLoader) {
        XposedHelpers.findAndHookMethod("order.a.c", classLoader, "getCount", new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                super.beforeHookedMethod(param);
            }

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
                XposedBridge.log("hook到订单列表的adapter的获取数据方法");
                Object obj = param.thisObject;
                XposedBridge.log(XposedHelpers.callMethod(obj, "getItem", 0).getClass().getName());
            }
        });
    }

    /**
     * hook fragment里面的数据初始化，得到该数据
     */
    public static void hookBaseFragmentInitList(ClassLoader classLoader) throws ClassNotFoundException {
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "a"
                , classLoader.loadClass("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment").getClass()
                , List.class
                , new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                        LogUtils.i("fragment的list的bean类是：" + ((List) param.args[1]).get(0).getClass().getName());
                    }

                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "a"
                , List.class
                , new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                        LogUtils.i("fragment的list的bean类是：" + ((List) param.args[0]).get(0).getClass().getName());
                    }

                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "b"
                , classLoader.loadClass("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment").getClass()
                , List.class
                , new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                        LogUtils.i("fragment的list的bean类是：" + ((List) param.args[0]).get(0).getClass().getName());
                    }

                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "b"
                , List.class
                , new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                        LogUtils.i("fragment的list的bean类是：" + ((List) param.args[0]).get(0).getClass().getName());
                    }

                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "c"
                , classLoader.loadClass("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment").getClass()
                , List.class
                , new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                        LogUtils.i("fragment的list的bean类是：" + ((List) param.args[0]).get(0).getClass().getName());
                    }

                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "c"
                , List.class
                , new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                        LogUtils.i("fragment的list的bean类是：" + ((List) param.args[0]).get(0).getClass().getName());
                    }

                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                    }
                });
    }

    /**
     * hook到订单确认页被创建，之后点击提交订单按钮
     *
     * @param classLoader
     */
    public static void hookOrderConfirmActivityOnCreate(ClassLoader classLoader) {
        XposedHelpers.findAndHookMethod("com.vdian.transaction.order.OrderConfirmActivity"
                , classLoader
                , "onCreate"
                , Bundle.class
                , new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                    }

                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        final Activity activity = (Activity) param.thisObject;
                        ThreadUtils.executeByCpuWithDelay(new ThreadUtils.SimpleTask<Object>() {
                            @Nullable
                            @Override
                            public Object doInBackground() throws Throwable {
                                return null;
                            }

                            @Override
                            public void onSuccess(@Nullable Object result) {
                                //点击 提交订单的按钮
                                ((TextView) XposedHelpers.getObjectField(activity, "j")).performClick();
                            }
                        }, 2, TimeUnit.SECONDS);
                    }
                });
    }

    public static Object objAllOrderFragment;

    public static void hookAllOrderFragmentOnCreate(ClassLoader classLoader) {
        XposedHelpers.findAndHookConstructor("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment", classLoader, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                super.beforeHookedMethod(param);
            }

            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
                LogUtils.i("AllOrderFragment执行了构造函数");
                objAllOrderFragment = param.thisObject;
                ThreadUtils.executeByCpuWithDelay(new ThreadUtils.SimpleTask<Object>() {
                    @Nullable
                    @Override
                    public Object doInBackground() throws Throwable {
                        return null;
                    }

                    @Override
                    public void onSuccess(@Nullable Object result) {
                        Object objOrder = ((List) XposedHelpers.getObjectField(objAllOrderFragment, "o")).get(0);
                        int can_jump_to_shop = (int) XposedHelpers.callMethod(objOrder, "getCan_jump_to_shop");
                        int can_merge_order = (int) XposedHelpers.callMethod(objOrder, "getCan_merge_order");
                        String express_price = (String) XposedHelpers.callMethod(objOrder, "getExpress_price");
                        int item_count = (int) XposedHelpers.callMethod(objOrder, "getItem_count");
                        String order_desc_url = (String) XposedHelpers.callMethod(objOrder, "getOrder_desc_url");
                        String order_detail_url = (String) XposedHelpers.callMethod(objOrder, "getOrder_detail_url");
                        String order_id = (String) XposedHelpers.callMethod(objOrder, "getOrder_id");
                        String order_integral = (String) XposedHelpers.callMethod(objOrder, "getOrder_integral");
                        String order_key = (String) XposedHelpers.callMethod(objOrder, "getOrder_key");
                        String order_source = (String) XposedHelpers.callMethod(objOrder, "getOrder_source");
                        String original_express_price = (String) XposedHelpers.callMethod(objOrder, "getOriginal_express_price");
                        long shop_id = (long) XposedHelpers.callMethod(objOrder, "getShop_id");
                        String shop_logo = (String) XposedHelpers.callMethod(objOrder, "getShop_logo");
                        String shop_name = (String) XposedHelpers.callMethod(objOrder, "getShop_name");
                        String shop_url = (String) XposedHelpers.callMethod(objOrder, "getShop_url");
                        String status_desc = (String) XposedHelpers.callMethod(objOrder, "getStatus_desc");
                        String total_price = (String) XposedHelpers.callMethod(objOrder, "getTotal_price");

                        WDTransBean wdTransBean = new WDTransBean(can_jump_to_shop, can_merge_order, express_price, item_count, order_desc_url
                                , order_detail_url, order_id, order_integral, order_key, order_source, original_express_price, shop_id, shop_logo
                                , shop_name, shop_url, status_desc, total_price);

                        LogUtils.i(GsonUtils.toJson(wdTransBean));

                    }
                }, 1, TimeUnit.SECONDS);
                ThreadUtils.executeByCpuWithDelay(new ThreadUtils.SimpleTask<Object>() {
                    @Nullable
                    @Override
                    public Object doInBackground() throws Throwable {
                        return null;
                    }

                    @Override
                    public void onSuccess(@Nullable Object result) {
                        LogUtils.i("主动执行loadData的方法");
                        XposedHelpers.callMethod(objAllOrderFragment, "onResume");
                    }
                }, 2, TimeUnit.SECONDS);
            }
        });

//        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
//                , classLoader
//                , "inflaterView"
//                , LayoutInflater.class
//                , ViewGroup.class
//                , Bundle.class
//                , new XC_MethodHook() {
//                    @Override
//                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
//                        super.beforeHookedMethod(param);
//                    }
//
//                    @Override
//                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//                        super.afterHookedMethod(param);
//                        LogUtils.i("baseOrderFragment inflaterView");
//                        LogUtils.i(param.thisObject.getClass().getSuperclass());
//                        final Object obj=param.thisObject;
//                        ThreadUtils.executeByCpuWithDelay(new ThreadUtils.SimpleTask<Object>() {
//                            @Nullable
//                            @Override
//                            public Object doInBackground() throws Throwable {
//                                return null;
//                            }
//
//                            @Override
//                            public void onSuccess(@Nullable Object result) {
//                                Object objOrder= ((List)XposedHelpers.getObjectField(obj,"o")).get(0);
//                                int can_jump_to_shop= (int) XposedHelpers.callMethod(objOrder,"getCan_jump_to_shop");
//                                int can_merge_order= (int) XposedHelpers.callMethod(objOrder,"getCan_merge_order");
//                                String express_price= (String) XposedHelpers.callMethod(objOrder,"getExpress_price");
//                                int item_count= (int) XposedHelpers.callMethod(objOrder,"getItem_count");
//                                String order_desc_url= (String) XposedHelpers.callMethod(objOrder,"getOrder_desc_url");
//                                String order_detail_url= (String) XposedHelpers.callMethod(objOrder,"getOrder_detail_url");
//                                String order_id= (String) XposedHelpers.callMethod(objOrder,"getOrder_id");
//                                String order_integral= (String) XposedHelpers.callMethod(objOrder,"getOrder_integral");
//                                String order_key= (String) XposedHelpers.callMethod(objOrder,"getOrder_key");
//                                String order_source= (String) XposedHelpers.callMethod(objOrder,"getOrder_source");
//                                String original_express_price= (String) XposedHelpers.callMethod(objOrder,"getOriginal_express_price");
//                                long shop_id= (long) XposedHelpers.callMethod(objOrder,"getShop_id");
//                                String shop_logo= (String) XposedHelpers.callMethod(objOrder,"getShop_logo");
//                                String shop_name= (String) XposedHelpers.callMethod(objOrder,"getShop_name");
//                                String shop_url= (String) XposedHelpers.callMethod(objOrder,"getShop_url");
//                                String status_desc= (String) XposedHelpers.callMethod(objOrder,"getStatus_desc");
//                                String total_price= (String) XposedHelpers.callMethod(objOrder,"getTotal_price");
//
//                                WDTransBean wdTransBean=new WDTransBean(can_jump_to_shop,can_merge_order,express_price,item_count,order_desc_url
//                                        ,order_detail_url,order_id,order_integral,order_key,order_source,original_express_price,shop_id,shop_logo
//                                        ,shop_name,shop_url,status_desc,total_price);
//
//                                LogUtils.i(GsonUtils.toJson(wdTransBean));
//
//                            }
//                        },1,TimeUnit.SECONDS);
//                    }
//                });
    }

    /**
     * hook阿里支付的请求，得到请求参数
     *
     * @param classLoader
     */
    public static void hookAliPayReq(ClassLoader classLoader) {
        XposedHelpers.findAndHookMethod("com.alipay.sdk.app.PayTask"
                , classLoader
                , "pay"
                , String.class
                , boolean.class
                , new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                        String reqInfo = (String) param.args[0];
                        LogUtils.i("阿里支付请求参数", reqInfo);
                        ToastUtils.showLong("已获取到阿里支付的支付参数 \n" + reqInfo);
                        FileUtils.writeFile(reqInfo, Constants.FILE_NAME_ALI);
                        param.setResult(null);
                    }

                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                    }
                });

        XposedHelpers.findAndHookMethod("com.alipay.sdk.app.PayTask"
                , classLoader
                , "h5Pay"
                , String.class
                , boolean.class
                , new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                        String reqInfo = (String) param.args[0];
                        LogUtils.i("阿里支付请求参数", reqInfo);
                        FileUtils.writeFile(reqInfo, Constants.FILE_NAME_ALI);
                        param.setResult(null);
                    }

                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                    }
                });
    }

    public static Object objBaseOrderFragment;

    /**
     * hook 所有的baseFragment里面的方法，看哪些方法是在什么时候调用的。
     */
    public static void hookAllMethodInBaseFragment(ClassLoader classLoader) throws Exception {
        objBaseOrderFragment=classLoader.loadClass("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment");
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "a"
                , classLoader.loadClass("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment")
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.a");
                        View view = (View) param.getResult();
                        LogUtils.i("view id=" + view.getId());
                    }
                });

        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "a"
                , classLoader.loadClass("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment")
                , classLoader.loadClass("com.vdian.android.wdb.order.model.response.RecommendItemListModel")
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.a");
                    }
                });

        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "a"
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.a");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "a"
                , classLoader.loadClass("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment")
                , List.class
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.a");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "a"
                , List.class
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.a");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "b"
                , classLoader.loadClass("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment")
                , List.class
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.b");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "b"
                , List.class
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.b");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "c"
                , classLoader.loadClass("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment")
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.c");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "c"
                , classLoader.loadClass("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment")
                , List.class
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.c");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "d"
                , classLoader.loadClass("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment")
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.d");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "f"
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.f");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "onHeadViewStateChange"
                , classLoader.loadClass("com.vdian.android.messager.core.WDMessage")
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.onHeadViewStateChange");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "a"
                , classLoader.loadClass("com.vdian.android.wdb.order.model.response.OpenPushResponse$ExtendEmergencyTip2")
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.a");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "a"
                , int.class
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.a");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "a"
                , int.class
                , boolean.class
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.a");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "b"
                , new XC_MethodHook() {
            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                super.afterHookedMethod(param);
                LogUtils.i("hook到方法 " + "BaseOrderFragment.b");
            }
        });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "b"
                , int.class
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.b");
                    }
                });
        //下面这4个方法，c c d e ,不知道为什么无法被hook。
//        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
//                , classLoader
//                , "c"
//                , new XC_MethodHook() {
//                    @Override
//                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//                        super.afterHookedMethod(param);
//                        LogUtils.i("hook到方法 " + "BaseOrderFragment.c");
//                    }
//                });
//        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
//                , classLoader
//                , "c"
//                , int.class
//                , new XC_MethodHook() {
//                    @Override
//                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//                        super.afterHookedMethod(param);
//                        LogUtils.i("hook到方法 " + "BaseOrderFragment.c");
//                    }
//                });
//        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
//                , classLoader
//                , "d"
//                , new XC_MethodHook() {
//                    @Override
//                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//                        super.afterHookedMethod(param);
//                        LogUtils.i("hook到方法 " + "BaseOrderFragment.d");
//                    }
//                });
//        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
//                , classLoader
//                , "e"
//                , new XC_MethodHook() {
//                    @Override
//                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//                        super.afterHookedMethod(param);
//                        LogUtils.i("hook到方法 " + "BaseOrderFragment.e");
//                    }
//                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "enableLazyLoad"
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.enableLazyLoad");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "g"
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.g");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "h"
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.h");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "i"
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.i");
                    }
                });
//        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
//                , classLoader
//                , "inflaterView"
//                , LayoutInflater.class
//                , ViewGroup.class
//                , Bundle.class
//                , new XC_MethodHook() {
//                    @Override
//                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//                        super.afterHookedMethod(param);
//                        LogUtils.i("hook到方法 " + "BaseOrderFragment.inflaterView");
//                    }
//                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "j"
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.j");
                    }
                });
        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
                , classLoader
                , "loadData"
                , new XC_MethodHook() {
                    @Override
                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                        super.afterHookedMethod(param);
                        LogUtils.i("hook到方法 " + "BaseOrderFragment.loadData");
                    }
                });
//        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
//                , classLoader
//                , "onDestroy"
//                , new XC_MethodHook() {
//                    @Override
//                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//                        super.afterHookedMethod(param);
//                        LogUtils.i("hook到方法 " + "BaseOrderFragment.onDestroy");
//                    }
//                });
//        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
//                , classLoader
//                , "onPullDownToRefresh"
//                , new XC_MethodHook() {
//                    @Override
//                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//                        super.afterHookedMethod(param);
//                        LogUtils.i("hook到方法 " + "BaseOrderFragment.onPullDownToRefresh");
//                    }
//                });
//        XposedHelpers.findAndHookMethod("com.vdian.android.wdb.order.fragment.base.BaseOrderFragment"
//                , classLoader
//                , "onPullUpToRefresh"
//                , new XC_MethodHook() {
//                    @Override
//                    protected void afterHookedMethod(MethodHookParam param) throws Throwable {
//                        super.afterHookedMethod(param);
//                        LogUtils.i("hook到方法 " + "BaseOrderFragment.onPullUpToRefresh");
//                    }
//                });

    }

    /**
     * hook 订单中心的recyclerView的adapter被创建时，得到该adapter的view控件。
     */
    public static void hookWDRecyclerViewOrderAdapterOnCreated(ClassLoader classLoader) throws Exception {
        XposedHelpers.findAndHookMethod("com.vdian.lib.pulltorefresh.recyclerview.WdRecyclerView"
                , classLoader
                , "setAdapter"
                , classLoader.loadClass("com.vdian.lib.pulltorefresh.recyclerview.adapter.BaseQuickAdapter")
                , new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        super.beforeHookedMethod(param);
                        LogUtils.i("adapter的类型是"+param.args[0].getClass().getName());
                    }
                });
    }

}
